import request from '@/utils/request'

// 定义公共的api
const BASE_URL = '/admin/system/sysUser'

export default {
  // 查询用户和分页
  getUserPageInfo(page, limit, searchObj) {
    return request({
      url: `${BASE_URL}/${page}/${limit}`,
      method: 'get',
      params: searchObj
    })
  },
  // 添加或者修改用户
  saveUser(user) {
    return request({
      url: `${BASE_URL}/addUser`,
      method: 'post',
      data: user
    })
  },
  // 根据id去得到一个用户
  getUserById(id) {
    return request({
      url: `${BASE_URL}/findUserById/${id}`,
      method: 'get'
    })
  },
  // 修改
  updateUser(user) {
    return request({
      url: `${BASE_URL}/updateUser`,
      method: 'post',
      data: user
    })
  },
  removeUserById(id) {
    return request({
      url: `${BASE_URL}/removeUserById/${id}`,
      method: 'delete'
    })
  },
  updateStatus(id, status) {
    return request({
      url: `${BASE_URL}/updateStatus/${id}/${status}`,
      method: 'get'
    })
  },
  // 根据用户id查询用户已分配的角色
  getRolesByUserId(userId) {
    return request({
      url: `${BASE_URL}/toAssign/${userId}`,
      method: 'get'
    })
  },

  // 分配角色
  assignRoles(assginRoleVo) {
    return request({
      url: `${BASE_URL}/doAssign`,
      method: 'post',
      data: assginRoleVo
    })
  }
}
